package ui;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

import core.PizzaStoreFacadeInterface;

import java.awt.*;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import ui.handlers.CustomerHandler;
import ui.handlers.MenuHandler;


public class KioskCustomerScreen extends BaseScreen /*implements ActionListener*/ {

	private JButton viewMenu_btn, createLogin_btn, login_btn;
	//private JTextField name_tf, street_tf, city_tf, state_tf, zip_tf, username_textfield;
	//private JCheckBox delivery_cb;
	
	private JFrame mainFrame;
	
	public JButton getViewMenuButton()
	{ return viewMenu_btn; }
	
	public JButton getCreateLoginButton()
	{ return createLogin_btn; }
	
	public JButton getLoginButton()
	{ return login_btn; }
	
	
	public KioskCustomerScreen(PizzaStoreFacadeInterface facade)
	{
		super(facade);
		mainFrame = new JFrame();
		mainFrame.setTitle("Kiosk Home Screen");
		mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		mainFrame.setSize(650, 550);
		mainFrame.setLayout(new GridLayout(3, 1));
		
		doTitle();	
		//doInfo();
		doButtons();
		
		mainFrame.setVisible(true);
		
	}
	
	private void doTitle()
	{
		String text = "<HTML><FONT SIZE = \"7\">" +
				"Pizza Kiosk Screen</FONT></HTML>";
			JLabel text_lbl = new JLabel(text);
			
			JPanel text_panel = new JPanel();
			text_panel.add(text_lbl);
			text_panel.setBorder(new EmptyBorder(30, 0 , 0, 0));
			
			mainFrame.add(text_panel);
	}
	
	private void doButtons()
	{
		viewMenu_btn = new JButton("View Menu");
		Font btnFont = new Font(viewMenu_btn.getName(),
		viewMenu_btn.getFont().getStyle(), 22);
		viewMenu_btn.setFont(btnFont);
		viewMenu_btn.addActionListener(new MenuHandler(this));
		
		createLogin_btn = new JButton("Create Login");
		createLogin_btn.setFont(btnFont);
		createLogin_btn.addActionListener(new CustomerHandler(this));
		
		login_btn = new JButton("Login");
		login_btn.setFont(btnFont);
		login_btn.addActionListener(new CustomerHandler(this));
		
		JPanel viewMenu_panel = new JPanel();
		viewMenu_panel.add(viewMenu_btn);
		
		JPanel createLogin_panel = new JPanel();
		createLogin_panel.add(createLogin_btn);
		
		JPanel login_panel = new JPanel();
		login_panel.add(login_btn);
		
		JPanel button_panel = new JPanel();
		button_panel.setLayout(new GridLayout(3, 1));
		button_panel.add(viewMenu_panel);
		button_panel.add(createLogin_panel);
		button_panel.add(login_panel);
		
		mainFrame.add(button_panel);
	}
	
	// To test the homescreen run this program with the following args:
	// localhost 1099 debug
	public static void main(String[] args) throws RemoteException
	{
		String hostname, port;
		
		if(args.length >= 2){
			port = args[1];
		}else{
			port = "1099";//default port
		}
		if(args.length >= 1){
			hostname = args[0];
		}else{
			hostname = "localhost";//default host
		}
		
		String url = "rmi://"+hostname+":"+port;
		
		PizzaStoreFacadeInterface facade = null;
		try {
			facade = (PizzaStoreFacadeInterface) Naming.lookup(url+"/"+"PizzaStoreFacade");
			System.out.println("Bound to PizzaStoreFacade");
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		new KioskCustomerScreen(facade);
		
	}
}